

import bpy

import 全局控制.Node.节点和插座基类.bl_节点基类 as 基类
import 全局控制.Node.插座.bl_插座基类 as 插件基类

from 全局控制.Node.节点数据类型 import bl_集合数据类型

import pdb

def f_物体数量update(self, context):
	差数 = len(self.m_Value) - self.m_物体_count
	#print('差数 = ', 差数)
	if 差数 > 0 :
		for i in range(差数):
			self.m_Value.remove(len(self.m_投影物体)-1)
	else:
		差数 = -差数
		for i in range(差数):
			self.m_Value.add()


class C_Node_物体组粒子(基类.C_SN_基类):
	bl_dname = 'bl_node_物体组粒子'
	bl_label = '物体组粒子'

	m_Value = bpy.props.CollectionProperty(type=bl_集合数据类型.C_物体组元素)
	m_物体_count = bpy.props.IntProperty(update=f_物体数量update, min=0)
	def init(self, context):
		super(C_Node_物体组粒子, self).f_init(context)
		self.outputs.new('C_NodeSocket_2D粒子集合', name='2D粒子集合')
		
		
	def draw_buttons(self, context, layout):
		layout.prop(self, "m_物体_count", text="count")
		col = layout.box()
		col = col.column()
		for c in self.m_Value:
			col.prop(c, "value", text="")
	
	def f_数据拷贝到输出插座中(self):
		输出插座 = self.outputs['物体']
		
		objs = []
		for c in self.m_Value:
			obj = c.value
			if obj != None:
				objs.append(obj)
		
		输出插座.f_setData(objs)

	'''def update(self):
		insocket = self.inputs['_>']
		if insocket.is_linked :
			if insocket.f_getData():
				self.f_数据拷贝到输出插座中()
			else:
				self.outputs['物体'].f_clear()'''
	def f_input插座Update(self, input插座, 上层Output=None):
		super(C_Node_物体组粒子, self).f_input插座Update(input插座, 上层Output)
		

	def f_update(self, 是否向下传递=False, input插座=None):
		输出插座 = self.outputs['2D粒子集合']
		
		super(C_Node_物体组粒子, self).f_update(是否向下传递, input插座)


	
class C_NODE_MENU_物体组粒子(bpy.types.Operator):
	bl_idname = 'node.global_node_objects_particle'
	bl_label = '物体组粒子'
	bl_options = {'REGISTER', 'UNDO'}
	
	def execute(operator, context):
		bpy.ops.node.add_node(type='C_Node_物体组粒子', use_transform=True)
		return {'FINISHED'}



classes = (
	C_Node_物体组粒子,
	C_NODE_MENU_物体组粒子,
	
)

def register():
	for c in classes:
		bpy.utils.register_class(c)
		
def unregister():
	for c in classes:
		bpy.utils.unregister_class(c)




